use "INSERTPATH\panel.dta", clear
cd "INSERTPATH"


**FIGURE 2. "violence", "undemocratic", "denial_oct" and "AEO" are the indices covering support for violence, undemocratic attitudes, election denial, and anti-establishment attitudes. The individual items within each index are also in the dataset, allowing for reconstruction of the indices. For instance, the "undem"-items are the individual undemocratic attitudes items, while the "viol"-items are the individual support for violence items. "authoritarian" is an indicator of PiS versus Pro-democratic alliance voter, based on Wave 1 vote choice, while "wave" is the wave indicator. "rid_w1" is a respondent identifier that is constant across the three waves. No other variables are used for Figure 3.
reg violence authoritarian##wave, cluster(rid_w1)
eststo violence
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2) size(medlarge)) ytitle("Support for Violence", size(medsmall)) legend(pos(12) size(vsmall) row(1))
graph save violence, replace

reg undemocratic authoritarian##wave, cluster(rid_w1)
eststo undemocratic
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Undemocratic Attitudes", size(medsmall)) legend(off)
graph save undemocratic, replace

reg denial_oct authoritarian##wave, cluster(rid_w1)
eststo denial_oct
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Election Denial", size(medsmall)) legend(off)
graph save denial_oct, replace

reg AEO authoritarian##wave, cluster(rid_w1)
eststo AEO
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Anti-Establishment Attitudes", size(medsmall)) legend(off)
graph save AEO, replace

grc1leg denial_oct.gph AEO.gph violence.gph undemocratic.gph, row(2) legendfrom(violence.gph) pos(12) title("")
graph display, ysize(9) xsize(10)
graph export figure2.pdf, replace



**FIGURE 3 (remember to install joyplot package, see Naqvi, A. (2023). reference in paper)
joyplot denial_oct if authoritarian == 1, by(wave)  bwid(.09) overlap(2) xtitle("") title("PiS", size(medlarge)) xlabel("") labs(4) palette(red*1.2 gs11  navy) yreverse laboffset(-.1)
graph save denial_pis_joy, replace
joyplot denial_oct if authoritarian == 0, by(wave)  bwid(.09) overlap(2) xtitle("") title("Pro-Democratic Alliance", size(medlarge)) xlabel("") labs(4) palette(orange green*2 red*1.2)  yreverse laboffset(-.1)
graph save denial_democratic_joy, replace
graph combine denial_pis_joy.gph denial_democratic_joy.gph, title("{bf:C: Election Denial}") ycommon imargin(14 14 6 3) ysize(5)
graph save denial_joy, replace

joyplot AEO if authoritarian == 1, by(wave)  bwid(.09) overlap(2) xtitle("") title("PiS", size(medlarge)) xlabel("") labs(4) palette(red*1.2 gs11 navy ) yreverse laboffset(-.1)
graph save AEO_pis_joy, replace
joyplot AEO if authoritarian == 0, by(wave)  bwid(.09) overlap(2) xtitle("") title("Pro-Democratic Alliance", size(medlarge)) xlabel("") labs(4) palette(orange green*2 red*1.2) yreverse laboffset(-.1)
graph save AEO_democratic_joy, replace
graph combine AEO_pis_joy.gph AEO_democratic_joy.gph, title("{bf:D: Anti-Establishment Attitudes}") ycommon imargin(14 14 6 3) ysize(5)
graph save aeo_joy, replace

joyplot undemocratic if authoritarian == 1, by(wave)  bwid(.09) overlap(2) xtitle("") title("PiS", size(medlarge)) xlabel("") labs(4) palette(red*1.2 gs11 navy ) yreverse laboffset(-.1)
graph save undemocratic_pis_joy, replace
joyplot undemocratic if authoritarian == 0, by(wave)  bwid(.09) overlap(2) xtitle("") title("Pro-Democratic Alliance", size(medlarge)) xlabel("") labs(4) palette(orange green*2 red*1.2) yreverse laboffset(-.1)
graph save undemocratic_democratic_joy, replace
graph combine undemocratic_pis_joy.gph undemocratic_democratic_joy.gph, title("{bf:B: Undemocratic Attitudes}") ycommon imargin(14 14 6 3) ysize(5)
graph save undemocratic_joy, replace

joyplot violence if authoritarian == 1, by(wave)  bwid(.09) overlap(2) xtitle("") title("PiS", size(medlarge)) xlabel("") labs(4) palette(red*1.2 gs11 navy ) yreverse laboffset(-.1)
graph save violence_pis_joy, replace
joyplot violence if authoritarian == 0, by(wave)  bwid(.09) overlap(2) xtitle("") title("Pro-Democratic Alliance", size(medlarge)) xlabel("") labs(4) palette(orange green*2 red*1.2) yreverse laboffset(-.1)
graph save violence_democratic_joy, replace
graph combine violence_pis_joy.gph violence_democratic_joy.gph, title("{bf:A: Support for Violence}") ycommon imargin(14 14 6 3) ysize(5)
graph save violence_joy, replace 

graph combine violence_joy.gph undemocratic_joy.gph denial_joy.gph aeo_joy.gph , row(4) imargin(tiny) ysize(7) b1title("Horizontal Axes Display Density on Full 0-1 Scales", size(small))
graph export figure3.pdf, replace







****FIGURE D1. Includes the indices of general trust in elections, online hostility and need for chaos (nfc).
reg general_trust_elections authoritarian##wave, cluster(rid_w1)
eststo denial_general
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("General Trust in Elections", size(medsmall)) legend(off)
graph save denial_general, replace

reg online_hostility authoritarian##wave, cluster(rid_w1)
eststo online_hostility
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Online Hostility", size(medsmall)) legend(off)
graph save online_hostility, replace

reg nfc authoritarian##wave, cluster(rid_w1)
eststo nfc
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2) row(1)) ytitle("Need for Chaos", size(medsmall)) legend(off)
graph save nfc, replace

grc1leg online_hostility.gph nfc.gph denial_general.gph, row(2) legendfrom(nfc.gph) pos(12) title("")
graph display, ysize(9) xsize(10)
graph export figureD1.pdf, replace


**FIGURE D2. This figure engages the (meta)perception measures, i.e., perceptions of PiS and PO voters' willingness to engage in antidemocratic practices ("undem") or political violence.
reg meta_violence_PO authoritarian##wave, cluster(rid_w1)
eststo metaPO_violence
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(.1 .2 .3 .4 .5 .6) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3") xtitle("") title("") legend(pos(2)) ytitle("Perception of PO: Violence") legend(pos(12) row(1))
graph save metaPO_violence, replace

reg meta_violence_PiS authoritarian##wave, cluster(rid_w1)
eststo metaPiS_violence
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(.1 .2 .3 .4 .5 .6) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3") xtitle("") title("") legend(pos(2)) ytitle("Perception of PiS: Violence") legend(pos(12) row(1))
graph save metaPiS_violence, replace

reg meta_undem_PO authoritarian##wave, cluster(rid_w1)
eststo metaPO_undem
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(.2 .3 .4 .5 .6 .7) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3") xtitle("") title("") legend(pos(2)) ytitle("Perception of PO: Undemocratic") legend(pos(12) row(1))
graph save metaPO_undem, replace

reg meta_undem_PiS authoritarian##wave, cluster(rid_w1)
eststo metaPiS_undem
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(.2 .3 .4 .5 .6 .7) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3") xtitle("") title("") legend(pos(2)) ytitle("Perception of PiS: Undemocratic") legend(pos(12) row(1))
graph save metaPiS_undem, replace

grc1leg metaPO_violence.gph metaPiS_violence.gph metaPO_undem.gph metaPiS_undem.gph, row(2) legendfrom(metaPO_violence.gph) pos(12) title("")
graph display, ysize(7) xsize(10)
graph export figureD2.pdf, replace


**FIGURE D3. This figure uses an alternative voter type indicator, "authoritarian2", which includes other voters apart from PiS and pro-democratic alliance voters.
reg violence authoritarian2##wave, cluster(rid_w1)
eststo violence
margins, at(wave =(1 2 3)) over(authoritarian2)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2) size(medlarge)) ytitle("Support for Violence", size(medsmall)) legend(pos(12) size(vsmall) row(1))
graph save violence, replace

reg undemocratic authoritarian2##wave, cluster(rid_w1)
eststo undemocratic
margins, at(wave =(1 2 3)) over(authoritarian2)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Undemocratic Attitudes", size(medsmall)) legend(off)
graph save undemocratic, replace

reg denial_oct authoritarian2##wave, cluster(rid_w1)
eststo denial_oct
margins, at(wave =(1 2 3)) over(authoritarian2)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Election Denial", size(medsmall)) legend(off)
graph save denial_oct, replace

reg AEO authoritarian2##wave, cluster(rid_w1)
eststo AEO
margins, at(wave =(1 2 3)) over(authoritarian2)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Anti-Establishment Attitudes", size(medsmall)) legend(off)
graph save AEO, replace

grc1leg denial_oct.gph AEO.gph violence.gph undemocratic.gph, row(2) legendfrom(violence.gph) pos(12) title("")
graph display, ysize(9) xsize(10)
graph export figureD3.pdf, replace




*************REPEATED CROSS SECTION AND ATTRITION (APPENDIX C AND A)
use "INSERT PATH\repeated_cross_section.dta", clear


**FIGURE C1. Uses the same indices as the panel analysis, just with this repeated cross section version of the dataset
reg violence authoritarian##wave
eststo violence
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2) size(medlarge)) ytitle("Support for Violence", size(medsmall)) legend(pos(12) size(vsmall) row(1))
graph save violence, replace

reg undemocratic authoritarian##wave
eststo undemocratic
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Undemocratic Attitudes", size(medsmall)) legend(off)
graph save undemocratic, replace

reg denial_oct authoritarian##wave
eststo denial_oct
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Election Denial", size(medsmall)) legend(off)
graph save denial_oct, replace

reg AEO authoritarian##wave
eststo AEO
margins, at(wave =(1 2 3)) over(authoritarian)
marginsplot, xline(1.5) ylabel(0 .2 .4 .6 .8 1) xlabel(1 "Wave 1" 1.5 "Election" 2 "Wave 2" 3 "Wave 3", labsize(small)) xtitle("") title("") legend(pos(2)) ytitle("Anti-Establishment Attitudes", size(medsmall)) legend(off)
graph save AEO, replace

grc1leg denial_oct.gph AEO.gph violence.gph undemocratic.gph, row(2) legendfrom(violence.gph) pos(12) title("")
graph display, ysize(9) xsize(10)
graph export figureC1.pdf, replace



**Attrition: Numbers for Table A1. Uses indicators of age, gender (reported as % female in A1), residence (reported as % urban in A1), education (reported as % university in A1), and party ID (reported as % PiS and PO in A1)
destring age_w1, gen(age)
bys wave: sum age if AEO != . | undemocratic !=. | violence !=. | denial_oct != .
bys wave: tab gender_w1 if AEO != . | undemocratic !=. | violence !=. | denial_oct != .
bys wave: tab urbanrural_w1 if AEO != . | undemocratic !=. | violence !=. | denial_oct != .
bys wave: tab education_w1 if AEO != . | undemocratic !=. | violence !=. | denial_oct != .
bys wave: tab partyid_w1 if AEO != . | undemocratic !=. | violence !=. | denial_oct != .